//
//  ZhuoZiList.m
//  HallView
//
//  Created by Lv Changye on 11-7-21.
//  Copyright 2011年 139me. All rights reserved.
//

#import "ZhuoZiList.h"

@implementation ZhuoZiList
@synthesize roomlist;

-(void)setRoomlist:(RoomList)rl{
	roomlist = rl;
	[[AppDelegate sharedDelegate]setRoomID:0];
	[zhuolist reloadData];

}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    
	roomlist = NewRoomListNon();
	socketLogin = [[AppDelegate sharedDelegate] mainsocket];
	eventLogin = [[AppDelegate sharedDelegate] eventLogin];
	
	IMP OnReceiveRoomList = [self methodForSelector:@selector(OnReceiveRoomList:)];
	[eventLogin AddCmd:hhcRoomList fun:(CMDFUN)OnReceiveRoomList];
	[eventLogin AddCmd:hchGetRoomList fun:(CMDFUN)OnReceiveRoomList];
	
	
    if (zhuolist==nil) {
        zhuolist=[[UITableView alloc]initWithFrame:CGRectMake(6, 63, 443, 218) style:UITableViewStylePlain];
        zhuolist.delegate=self;
        zhuolist.dataSource=self;
        zhuolist.backgroundColor=[UIColor clearColor];
        zhuolist.separatorStyle=UITableViewCellSeparatorStyleNone;
    }
    zhuolist.clipsToBounds=YES;
    [zhuolist.layer setCornerRadius:10.0f];
    [self.view addSubview:zhuolist];
    [super viewDidLoad];
	
    // Do any additional setup after loading the view from its nib.
}

- (void)OnReceiveRoomList:(SocketEngine *)socket{
	NSLog(@"加载RoomList开始");
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(IBAction)wanjiaPaiXu{

}
-(IBAction)suduPaiXu{
    
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark --TableViewDelegate--
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return roomlist.num;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //NSInteger section=[indexPath section];
    NSUInteger row=[indexPath row];
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
	if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier]autorelease];
    }
    cell.textLabel.text=NewRoomListString(roomlist, row);
    cell.textLabel.font=[UIFont systemFontOfSize:15];
    //cell.backgroundColor=[UIColor clearColor];
    
    cell.textLabel.backgroundColor=[UIColor clearColor];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //[tableView deselectRowAtIndexPath:indexPath animated:YES];
	NSUInteger row=[indexPath row];
	if (row > roomlist.num - 1) {
		return;
	}
	[[AppDelegate sharedDelegate] cmdGetRoomInfo:socketLogin withRoomId:roomlist.room[row].roomId];
	[[AppDelegate sharedDelegate] setRoomID:roomlist.room[row].roomId];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 25;
}
@end
